Post not yet marked as solved
Hi Claude31,I try it, but it doesn't work.Radio button hasn't changed the background color.
Not working,I have a pdf with 2 signature fields, the first is signed, the second is not signed.The test for signing for both fields returns false, and annot.contents is for both nilEDIT:I think it's a bug in PDFAnnotation, when I tried other PDF SDK so the check on Content works.EDIT2:The property of annotation "widgetStringValue" represents the value of the given annotation. It works for text, checkbox, radio and just some signature fields. Some signature fields don't work and I don't know why.
Still not working,but you have right, it is not a good idea to draw textfield directly, but I should set it in context.How do I set it there?
Hi,I have ViewController: import UIKit
import PDFKit
class ViewController: UIViewController, PDFDocumentDelegate {
@IBOutlet weak var pdfView: PDFView?
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if let documentURL = Bundle.main.url(forResource: "Untitled12", withExtension: "pdf") {
if let document = PDFDocument(url: documentURL) {
pdfView?.autoScales = true
pdfView?.backgroundColor = UIColor.lightGray
document.delegate = self
pdfView?.document = document
}
}
}
func classForPage() -> AnyClass {
return CustomPage.self
}
}And CustomPage:class CustomPage: PDFPage {
override func draw(with box: PDFDisplayBox, to context: CGContext) {
super.draw(with: box, to: context)
UIGraphicsPushContext(context)
context.saveGState()
let pageBounds = self.bounds(for: box)
context.translateBy(x: 0.0, y: pageBounds.size.height)
context.scaleBy(x: 1.0, y: -1.0)
context.rotate(by: CGFloat.pi / 4.0)
let string: NSString = "Custom string"
let attributes = [
NSAttributedStringKey.foregroundColor: UIColor(red: 0.5, green: 0.5, blue: 0.5, alpha: 0.5),
NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 64)
]
// THIS WORK PERFECTLY:
string.draw(at: CGPoint(x:250, y:40), withAttributes: attributes)
// THIS DOESNT WORK:
let sampleTextField = UITextField(frame: CGRect(x: 20, y: 100, width: 300, height: 40))
sampleTextField.placeholder = "Enter text here"
sampleTextField.font = UIFont.systemFont(ofSize: 15)
sampleTextField.autocorrectionType = UITextAutocorrectionType.no
sampleTextField.draw(CGRect(x: 20, y: 100, width: 300, height: 40))
context.restoreGState()
UIGraphicsPopContext()
}
}I want to render textfields, radio button, checkboxies and signature fileds. In signature fields I want to add custom tapped action when I tapped to annotation.